/**
 * Copyright (c) 2024,  科泰集团教研团队
 * 版权所有，请勿侵权
 */
package service;

import dao.PetDao;
import dao.PetDaoOracleImpl;
import entity.Pet;
import factory.PetDaoFactory;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author 科泰集团教研团队
 * @version 1.0.0
 * @packageName service
 * @fileName PetServiceImpl.java
 * @createTime 2024/9/5 17:35
 * @lastModify 2024/9/5 17:35
 */
@Service("petService")
public class PetServiceImpl implements PetService {
    // 通过指定的名称获取PetDao实例
//    @Autowired
//    @Qualifier("petDao")
//    @Resource(name = "petDaoMySQL")
    @Resource(type = PetDaoOracleImpl.class)
    private PetDao petDao;

    public PetDao getPetDao() {
        return petDao;
    }

    public void setPetDao(PetDao petDao) {
        this.petDao = petDao;
    }

    @Override
    public boolean save(Pet pet) {
        int rows = petDao.insert(pet);
        delay(3000);// 模拟执行业务3秒，注意：这里把抛出异常代码删除
        return rows > 0;
    }

    @Override
    public boolean modify(Pet pet) {
        delay(2000);// 模拟执行业务2秒
        return false;
    }

    @Override
    public boolean del(Integer id) {
        delay(1000);// 模拟执行业务1秒
        return false;
    }

    // 模拟业务执行所需的时间
    private void delay(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
